import numpy as np

# 大型数组运算,需要在大数据集(比如数组或网络)上面执行计算
def demo_1():
    ax = np.array([1,2,3,4])
    ay = np.array([5,6,7,8])
    print(ax * 2)
    print(ax + 10)
    print(ax * ay)
    print(ax + ay)

# 底层实现中,NumPy数组使用了C或者Fortran语言的机制分配内存,是一个非常大的连续的并由同类型数据组成的内存区域
def demo_2():
    grid = np.zeros(shape=(10000, 10000), dtype=float)
    print(grid)
    grid += 10
    print(grid)
    print(np.sin(grid))

def demo_3():
    a = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12], [13,14,15,16]])
    print(a)
    print(a[1])
    print(a[:,1])
    print(a[1:3, 1:3])
    print(a[1:3, 1:3] + 10)
    # 将大于10的元素替换为10
    print(np.where(a < 10, a, 10))

if __name__ == '__main__':
    demo_1()
    demo_2()
    demo_3()